<?php
namespace Model;

use Hoa\Registry\Registry;
use Library\Db;


/**
 * @name Card
 * @desc Card模型
 * @author Los
 */
class Card extends BaseModel {
	/**
	 * 构造函数
	 */
	public function __construct() {
		parent::__construct();
	}


	/**
	 * test
	 */
	static public function test() {
		return __METHOD__;
	}


	/**
	 * 修改卡
	 * @param array $data
	 * @param string $code
	 * @return bool
	 */
	static public function saveCardByCode($data, $code) {
		$conf = Registry::get('conf');
		$dbConf = $conf['database']['mydb'];
		$db = new Db($dbConf);
		$db->where('code', $code);
		$result = $db->update('card', $data);
		return $result;
	}


	/**
	 * 查询新卡编码列表
	 */
	static public function getNewCardCodeList($pagesize) {
		$conf = Registry::get('conf');
		$dbConf = $conf['database']['mydb'];
		$db = new Db($dbConf);
		$fieldList = ['id', 'code'];
		$db->where('sold', 0);
		$code_list = $db->map('id')->get('card', $pagesize, $fieldList);
		return $code_list;
	}



}

